# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname=opensearch-security-plugin
pkgver=2.6.0.0
pkgrel=1
_opensearchver=2.6.0
_jdkver=11
pkgdesc="OpenSearch Security Plugin"
arch=('loong64' 'x86_64')
url="https://opensearch.org/docs/latest/security-plugin"
license=('Apache')
depends=("opensearch=${_opensearchver}")
makedepends=("java-environment=${_jdkver}" 'unzip' 'git')
source=("git+https://github.com/opensearch-project/security.git#tag=${pkgver}") # Build requires git
sha256sums=('SKIP')

build() {
  cd "security"
  export JAVA_HOME="/usr/lib/jvm/java-${_jdkver}-openjdk"
  export PATH="/usr/lib/jvm/java-${_jdkver}-openjdk/bin:$PATH"
  export GRADLE_OPTS="-Dbuild.snapshot=false -Dopensearch.version=${_opensearchver}"

  # Currently the tests don't provide a way to skip the integration tests
  # … so we skip them entirely for now
  ./gradlew assemble
}

package() {
  install -dm755 "${pkgdir}/usr/share/opensearch/plugins/opensearch-security"
  cd "${pkgdir}/usr/share/opensearch/plugins/opensearch-security"
  unzip "${srcdir}/security/build/distributions/opensearch-security-${pkgver}.zip"

  install -Dm644 "${srcdir}/security/LICENSE.txt" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"
}
